# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=qtile
pkgver=0.23.0
_commit=951aa6345712b4f798e3e2669f7d905e23690405  # refs/tags/v0.23.0
pkgrel=2
pkgdesc="A full-featured, pure-Python tiling window manager"
arch=(loong64 x86_64)
url="http://www.qtile.org"
_url="https://github.com/qtile/qtile"
license=(MIT)
depends=(
  gdk-pixbuf2
  glibc
  libnotify
  librsvg
  pango
  python
  python-cairocffi
  python-cffi
  python-gobject
  python-pywlroots
  python-xcffib
  wlroots0.16
)
makedepends=(
  git
  libpulse
  python-build
  python-installer
  python-setuptools-scm
  python-wheel
)
checkdepends=(
  graphviz
  gtk3
  imagemagick
  lm_sensors
  procps-ng
  python-bowler
  python-dbus-next
  python-gobject
  python-pytest
  python-xdg
  xorg-server-xephyr
  xorg-server-xvfb
  xorg-xrandr
  xorg-xwayland
)
optdepends=(
  'alsa-utils: for volume widget'
  'canto-daemon: for canto widget'
  'cmus: for cmus widget'
  'jupyter_console: for interaction with qtile via Jupyter'
  'khal: for khal_calendar widget'
  'libinput: for Wayland backend'
  'libpulse: for pulse_volume and pulseaudio_ffi widget'
  'lm_sensors: for sensors widget'
  'moc: for moc widget'
  'python-bowler: for migrating configuration files'
  'python-dbus-next: for utils, notifications and several widgets'
  'python-iwlib: for wlan widget'
  'python-keyring: for imapwidget widget'
  'python-mpd2: mpd2widget widget'
  'python-psutil: graph, net and memory widget'
  'python-pywlroots: for Wayland backend'
  'python-setproctitle: change process name to qtile'
  'python-xdg: launchbar widget'
  'xorg-xwayland: for XWayland support'
)
install=$pkgname.install
source=("git+$_url#tag=$_commit?signed")
sha512sums=('SKIP')
b2sums=('SKIP')
validpgpkeys=(
  '3CCAB226289DE0160C61BDB418D18F1BC464DCA3' # Tycho Andersen <tycho@tycho.pizza>
  '35D92E7CC7357A81173EA1C974F9FDD20984FBEC' # Matt Colligan <mcol@posteo.net>
  'A6BAA1E17D2664ADB97B2C6F58A9AA7C86727DF7' # elParaguayo <elparaguayocode@gmail.com>
)

build() {
  export CFLAGS="$CFLAGS -I/usr/include/wlroots0.16"
  export LDFLAGS="$LDFLAGS -L/usr/lib/wlroots0.16"
  cd $pkgname
  PYTHONPATH="$PWD" ./scripts/ffibuild -v
  python -m build --wheel --no-isolation
}

check() {
  local pytest_options=(
    -vv
    --backend x11
    --backend wayland
  )
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $pkgname
  # install to temporary location, as importlib is used
  python -m installer --destdir=test_dir dist/*.whl
  export LC_TYPE=en_US.UTF-8
  export PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH"
  pytest "${pytest_options[@]}"
}

package() {
  depends+=(libwlroots.so=11)
  cd $pkgname
  python -m installer --destdir="$pkgdir" dist/*.whl
  # license
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  # config
  install -vDm 644 libqtile/resources/default_config.py -t "$pkgdir/usr/share/doc/$pkgname/"
  # desktop files
  install -vDm 644 "resources/$pkgname.desktop" -t "$pkgdir/usr/share/xsessions/"
  install -vDm 644 "resources/$pkgname-wayland.desktop" -t "$pkgdir/usr/share/wayland-sessions/"
  # docs
  install -vDm 644 {CHANGELOG,README.rst} -t "$pkgdir/usr/share/doc/$pkgname/"
}
